package com.bawei.mdm2207alast.mine.ask

import com.bawei.mdm2207alast.base.BaseViewModel
import com.bawei.mdm2207alast.base.IUiIntent
import com.bawei.mdm2207alast.model.db.AskDao
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

/**
 * 作者：赵亮
 * 时间：2024/12/24 11:59
 * 功能：
 */
@HiltViewModel
class AskViewModel @Inject constructor(private val askDao: AskDao) : BaseViewModel() {
    override fun handIntent(it: IUiIntent) {
        when (it) {
            // 提交请假
            is AskIntent.CommitAsk -> roomRequest(flow { emit(askDao.insert(it.askEntity)) })
            // 根据用户id查询请假列表
            is AskIntent.SelAsk -> roomRequest(flow { emit(askDao.selectByUid(it.uid)) })
            // 查询所有待审批请假列表
            is AskIntent.SelAskNoApprove -> roomRequest(flow { emit(askDao.selectNoApprove()) })
            // 审批
            is AskIntent.UpdateIntent -> roomRequest(flow { emit(askDao.update(it.askEntity)) })
        }
    }
}